package inherit;

// 继承
public class inherit {
    public static void main(String[] args) {
        Student student = new Student();
        student.setName("小明");
        student.setAge(18);
        student.setFraction(12);

        String name = student.getName();
        int age = student.getAge();
        int fraction = student.getFraction();
        System.out.println(name + " " + age + " " + fraction);
    }

    static class Person {
        /*
         * private: 子类无法访问父类定义的变量
         * protected: 子类可以访问父类定义的变量
         * */
        protected char gender = '男';
        private String name;
        private int age;

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public int getAge() {
            return age;
        }

        public void setAge(int age) {
            this.age = age;
        }
    }

    static class Student extends Person {
        private int fraction;

        public int getFraction() {
            return fraction;
        }

        public void setFraction(int fraction) {
            System.out.println("gander = " + super.gender);
            this.fraction = fraction;
        }
    }
}
